home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-07-15 | 5.0 KB | 161 lines | [TEXT/MPS ] |
- { © Copyright 1990,1991 The NetWork Project, StatLab Heidelberg.
- © Copyright 1990,1991 Joachim Lindenberg, Karlsruhe. All rights reserved. }
-
- program ScreenSaver;
-
- uses MemTypes, QuickDraw, OSIntf, ToolIntf, SysEqu, Traps;
-
- PROCEDURE InitToolBox;
- VAR
- i : integer;
- p : GrafPtr;
- m : MenuHandle;
-
- BEGIN
- MaxApplZone;
- FOR i := 1 TO 10 DO
- MoreMasters;
- InitGraf(@thePort); {initialize QuickDraw}
- InitFonts; {initialize Font Manager}
- InitWindows; {initialize Window Manager}
- InitMenus; {initialize Menu Manager}
- TEInit; {initialize TextEdit}
- InitDialogs(NIL); {initialize Dialog Manager}
- InitCursor; {call QuickDraw to make cursor (pointer) an arrow}
-
- m := GetMenu (256);
- AddResMenu (m, 'DRVR');
- InsertMenu (m, 0);
- { m := GetMenu (257); InsertMenu (m, 0); }
- END;
-
- type RgnHPtr = ^RgnHandle; IntPtr = ^integer;
- PtPtr = ^Point;
-
- var mousergn : RgnHandle; frontmost : boolean;
- ev : EventRecord;
- mousepos : Point; w : WindowPtr; sysv : longint;
- count, sleep : integer;
- savedmbarheight : integer;
-
- procedure OpenFullScreenWindow (var w : WindowPtr);
-
- var savedgrayrgn, newgrayrgn : RgnHandle;
- pw : integer; box : Rect;
-
- begin
-
- { Warning: If you are going to modify this screensaver, be sure not to add
- code between this line and the line Note: below. Otherwise the system
- may crash, because the grayrgn points to garbage. If you feel you absolutely
- must add code in this part of the program, then please change the process
- type to pMaster, and back to pSlave below. }
-
- { calculate union of screenbits and grayrgn => total space of all screens }
-
- savedgrayrgn := RgnHPtr (GrayRgn)^;
- newgrayrgn := NewRgn; RectRgn (newgrayrgn, screenbits.bounds);
- UnionRgn (savedgrayrgn, newgrayrgn, newgrayrgn);
- RgnHPtr (GrayRgn)^ := newgrayrgn; box := newgrayrgn^^.RgnBBox;
-
- { set up full screen transparent window }
-
- w := NewWindow (nil, box, '', false,
- plainDBox, WindowPtr (-1), false, 0);
-
- pw := IntPtr (PaintWhite)^; IntPtr (PaintWhite)^:= 0;
- ShowWindow (w); SetPort (w);
- IntPtr (PaintWhite)^:= pw;
-
- { restore grayrgn }
-
- RgnHPtr (GrayRgn)^ := savedgrayrgn;
- {DisposeRgn (newgrayrgn);}
- if IntPtr (MBarHeight)^ = 0 then w^.visrgn := newgrayrgn;
- { A/UX 2.0 & 7.0 resets visible on ShowWindow -- this is a bug
- forcing this with >= 6.0.5 is OK }
- InvalRgn (newgrayrgn);
-
- { Note: grayrgn restored }
- IntPtr (MBarHeight)^ := savedmbarheight;
- end;
-
- const _AUXDispatch = $ABF9;
-
- function TrapAvail (trap : integer) : boolean;
- begin
- TrapAvail := NGetTrapAddress (trap, TrapType (trap >= $A800))
- <> NGetTrapAddress (_Unimplemented, ToolTrap)
- end;
-
- procedure ErrorExit (err : integer);
- begin
- if err <> noErr then if TrapAvail (_DebugStr) then DebugStr ('Screensaver detected error'); { ExitToShell; }
- end;
-
- var sysenv : SysEnvRec;
-
- begin
- InitToolBox;
- w := nil; count := 5; sleep := 0;
- frontmost := true;
-
- savedmbarheight := IntPtr (MBarHeight)^;
- if SysEnvirons (1, sysenv) = noErr then;
- if (sysenv.systemVersion >= $700) | TrapAvail (_AUXDispatch) then IntPtr (MBarHeight)^ := 0;
-
- { we want to exit if either NetWork Processor tells us to exit, or if
- we detect some user activity ourselves. In the latter case, Multifinder
- will hand us an event which we ignore. The use of a mouse moved event
- allows us to use a large sleep value. If we want to detect modifiers
- in a timely manner, we would have to use a smaller value (modifiers
- are detected by NetWork Processor, but not by Multifinder. }
-
- { set mousergn to current mouse position }
-
- mousepos := PtPtr (Mouse)^;
- { GetMouse (mousepos); LocalToGlobal (mousepos); }
- mousergn := NewRgn;
- with mousepos do SetRectRgn (mousergn, h, v, h+1, v+1);
-
- repeat
- ObscureCursor; { background InitCursors not shielded by Multifinder }
-
- if WaitNextEvent (EveryEvent, ev, sleep, mousergn) then
- case ev.what of
- updateEvt : begin
- BeginUpdate (w);
- FillRgn (w^.visRgn, black);
- EndUpdate (w);
- end;
- diskEvt : if Point (ev.message).v <> noErr then
- if Eject (nil, Point (ev.message).h) <> noErr then;
- { cannot handle bad disk, because this causes a modal dialog
- => NetWork Processor will kill us. Eject the disk instead. }
- app4Evt : if BAnd (ev.message, $ff000000) = $01000000 then begin
- frontmost := odd (ev.message);
- if frontmost & (w = nil) then begin
- count := 5; sleep := 0;
- end
- else if frontmost | (w = nil) then ev.what := nullEvent
- { else exit }
- end;
-
- { otherwise DebugStr ('some other event'); }
- end;
-
- { inclusion of app4Evt causes us to exit if another program is launched frontmost.
- if screensaver does not exit, you won´t see anything. filter app4Evts if you
- want a different behaviour. Note that app4Evt can be a mousemoved evt too. }
-
- if frontmost & (w = nil) then
- if count > 0 then count := count - 1
- else if count = 0 then OpenFullScreenWindow (w)
- else
- else sleep := 60;
-
- until ev.what in [keydown, mousedown, diskEvt, app4Evt];
-
- if w <> nil then DisposeWindow (w); { forces update of all windows }
- end.
-